#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < int > vec;
typedef pair < int , int > pii;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 310;

int C[N][N],p,n,m,mod,hav[N],s[N],f[N][N];

void solve() {
    memset(hav,0,sizeof hav); memset(s,0,sizeof s); memset(C,0,sizeof C); memset(f,0,sizeof f);
    n = in,m = in,mod = in; for(int i = 0;i <= n;i++) C[i][0] = 1;
    for(int i = 1;i <= n;i++)
	for(int j = 1;j <= i;j++)
	    C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
    for(int i = 1;i <= m;i++) { int p = in,q = in; hav[q]++; }
    for(int i = n;i >= 1;i--) s[i] = s[i + 1] + hav[i];
    for(int i = 1;i <= n;i++) if(s[i] > n - i + 1) return puts("NO"),void();
    f[n][0] = 1;
    for(int i = n;i >= 1;i--)
	for(int j = 0;j <= n;j++)
	    if(f[i][j]) {
		int lim = n - i + 1 - j - s[i];
		for(int k = 0;k <= lim;k++)
		    f[i - 1][j + k] = (f[i - 1][j + k] + (ll) f[i][j] * C[n - m - j][k] % mod) % mod;
	    }
    printf("YES %d\n",f[0][n - m]);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    for(int T = in;T;T--) solve();
}
